﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet
{
    /// <summary>
    ///     包基类
    /// </summary>
    public abstract class Package
    {
        /// <summary>
        ///     包的发送时间
        /// </summary>
        public DateTime SendTime;
        /// <summary>
        ///     包是否加密
        /// </summary>
        public bool IS_ENCRYPT;
        /// <summary>
        ///     包是否需要回复
        /// </summary>
        public bool IS_ACK;
        /// <summary>
        ///     包头数据
        /// </summary>
        public String Header;
        /// <summary>
        ///     包体数据
        /// </summary>
        public Dictionary<String, byte[]> Body;
        /// <summary>
        ///     网络协议簇
        /// </summary>
        public Protocol.NetworkProtocol Protocol;
        /// <summary>
        ///     网络命令
        /// </summary>
        public Protocol.IN_NetworkCommand Command;
        /// <summary>
        ///     得到包体长度
        /// </summary>
        public int GetLength()
        {
            return int.Parse(Encoding.Default.GetString(this.Body["Length"]));
        }
        /// <summary>
        ///     加密包体
        /// </summary>
        /// <returns>
        ///     返回加密后的包体数据
        /// </returns>
        public abstract byte[] EncryptBody();
        /// <summary>
        ///     解密包体
        /// </summary>
        /// <returns>
        ///     返回解密后的包体数据
        /// </returns>
        public abstract byte[] DecryptBody();
        /// <summary>
        ///     验证包
        /// </summary>
        /// <returns>
        ///     返回true , 则表示验证成功 
        /// </returns>
        public abstract bool ValidataPackage();
        /// <summary>
        ///     得到包协议簇
        /// </summary>
        /// <returns>
        ///     返回该包的协议簇
        /// </returns>
        public abstract Protocol.NetworkProtocol GetProtocol();
        /// <summary>
        ///     得到包HASHCODE
        /// </summary>
        /// <returns>
        ///     返回该包HASHCODE
        /// </returns>
        public abstract new String GetHashCode();
        /// <summary>
        ///     得到包名称
        /// </summary>
        /// <returns>
        ///     返回包名称
        /// </returns>
        public abstract String GetPackageName();
        /// <summary>
        ///     得到包头部
        /// </summary>
        /// <returns>
        ///     返回包头部
        /// </returns>
        public String GetHeader()
        {
            return this.Header;
        }
        /// <summary>
        ///     得到包加密起始位置
        ///     如果该包不是加密的返回 -1
        /// </summary>
        /// <returns>
        ///     返回加密起始位置
        /// </returns>
        public abstract int GetcryptograshStart();
        /// <summary>
        ///     得到包体数据
        /// </summary>
        /// <returns>
        ///     返回包体数据
        /// </returns>
        public abstract Dictionary<String, byte[]> GetBody();
        /// <summary>
        ///     得到包类型
        /// </summary>
        /// <returns>
        ///     返回包类型
        /// </returns>
        public abstract String GetType();
    }
}
